import React, { Component } from 'react'
import { HashRouter as Router, Link, Route } from 'react-router-dom'

class Index extends Component {
  render() {
    return <h1>首页</h1>
  }
}
class User extends Component {
  render() {
    return <h1>用户</h1>
  }
}
let routes = [
  {
    path: "/index",
    key: "index",
    component: Index
  },
  {
    key: "user",
    path: "/user",
    component: User
  }
]
export default class App extends Component {
  render() {
    return (
      <div>
        <Router>
          <Link to='/index'>首页</Link>
          <Link to='/user'>用户</Link>
          {routes.map((route, i) => {
            return <Route path={route.path} key={route.key} render={(props) => {
              return <route.component></route.component>
            }}></Route>
          })
          }
        </Router>
      </div>
    )
  }
}
